import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		// 筛选数据
		sortData: {
			nearlyShop: []
		},
		// 购物车列表
		cartList: []
	},
	mutations: {
		// 存储附近商家数据
		setNearlyShop(state,listData = []){
			state.sortData = {
				nearlyShop:listData
			}
		},
		// 更新购物车
		updateCart(state, goodsInfo) {
			state.cartList = state.cartList.filter(item => {
				return item.gid !== goodsInfo.gid
			})
			if (goodsInfo.count) {
				state.cartList.push(goodsInfo)
			}
		},
		// 清空购物车
		clearCart(state) {
			state.cartList = []
		}
	},
	actions: {}
})
export default store
